/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gen2phen.labs.actions;

import java.util.ArrayList;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import org.gen2phen.labs.domain.Disease;
import org.gen2phen.labs.domain.Gene;
import org.gen2phen.labs.services.Loader;

/**
 *
 * @author pedrolopes
 *
 * GEN2PHEN Semantic Web Labs: Knowledge Netowork
 *
 */
@UrlBinding("/gene/{$event}/{query}")
public class GeneActionBean implements ActionBean {

    private ActionBeanContext context;
    private String query;
    private Gene gene;
    private ArrayList<Disease> diseases = new ArrayList<Disease>();

    public ArrayList<Disease> getDiseases() {
        return diseases;
    }

    public void setDiseases(ArrayList<Disease> diseases) {
        this.diseases = diseases;
    }

    public Gene getGene() {
        return gene;
    }

    public void setGene(Gene gene) {
        this.gene = gene;
    }

    public String getQuery() {
        return query;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public ActionBeanContext getContext() {
        return context;
    }

    /**
     * Main handler load Disease and Drug information for the given gene (in query).
     *
     * @return Redirect to main web application page.
     */
    @DefaultHandler
    public Resolution view() {

        if (Loader.loadByGene(query)) {
            // load gene info
            gene = Loader.genes.get(query);
            for (Disease d : gene.getDiseases().values()) {
                // add Gene diseases to global disease array list (used in .jsp)
                diseases.add(d);
            }
        }

        return new ForwardResolution("/gene.jsp");
    }
}
